package com.andnnl.num;

import java.sql.SQLOutput;
import java.util.Arrays;

/**
 * Created by chenss on 2021/4/8.
 */
public class MoveZeroTest {
    public static void main(String[] args) {
        int[] nums={123,523,690,0,0,4,83,95,0,2};
        moveZeroes2(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i]);
            System.out.print("\t");
        }
    }

    public static void moveZeroes2(int[] nums) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0 ) {
                int t = nums[index];
                nums[index++] = nums[i];//把遇到非0的放到前面来
                nums[i] = t;//
            }
        }

    }
}
